package cn.ocean.basic.service.impl;

import cn.ocean.basic.mapper.BaseMapper;
import cn.ocean.basic.query.BaseQuery;
import cn.ocean.basic.service.IBaseService;
import cn.ocean.basic.utils.PageList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {


    @Autowired
    
    private BaseMapper<T> baseMapper;

    /**
     * @Title: 查询所有
     * @Description: TODO
     * @Author: Fill
     * @Version: 1.0
     * @Date:  19:28 19:28
     * @Parameters: []
     * @Return java.util.List<cn.ocean.org.domain.T>
     */
    @Override
    public List<T> loadAllDept() {
        return baseMapper.loadAllDept();
    }

    /**
     * @Title: 根据id查询
     * @Description: TODO
     * @Author: Fill
     * @Version: 1.0
     * @Date:  19:29 19:29
     * @Parameters: [id]
     * @Return cn.ocean.org.domain.T
     */
    @Override
    public T getByIdDept(Long id) {
        return baseMapper.getByIdDept(id);
    }

    /**
     * @Title: 删除
     * @Description: TODO
     * @Author: Fill
     * @Version: 1.0
     * @Date:  19:29 19:29
     * @Parameters: [id]
     * @Return void
     */
    @Override
    @Transactional
    public void delDept(Long id) {
        baseMapper.delDept(id);
    }

    /**
     * @Title: 修改
     * @Description: TODO
     * @Author: Fill
     * @Version: 1.0
     * @Date:  19:29 19:29
     * @Parameters: [id]
     * @Return void
     */
    @Override
    @Transactional
    public void updateDept(T t) {
        baseMapper.updateDept(t);
    }

    /**
     * @Title: 增加
     * @Description: TODO
     * @Author: Fill
     * @Version: 1.0
     * @Date:  19:30 19:30
     * @Parameters: [t]
     * @Return void
     */
    @Override
    @Transactional
    public void addDept(T t) {
        baseMapper.addDept(t);
    }

    /**
     * @Title:  分页加高级查询
     * @Description: TODO
     * @Author: Fill
     * @Version: 1.0
     * @Date:  19:30 19:30
     * @Parameters: [tQuery]
     * @Return cn.ocean.basic.utils.PageList<cn.ocean.org.domain.T>
     */
    @Override
    public PageList<T> queryData(BaseQuery baseQuery) {

        // 当前页数据
        List<T> data = baseMapper.queryData(baseQuery);
        // 查询分页总条数
        Integer total = baseMapper.queryCount(baseQuery);

        return new PageList<>(total, data)  ;
    }


    /**
     * @Title: batchDel
     * @Description: 批量删除
     * @Author: Fill
     * @Version: 1.0
     * @Date:  2022/6/26 14:38
     * @Parameters: [ids]
     * @Return void
     */
    @Override
    @Transactional
    public void batchDel(Long[] ids) {
        baseMapper.batchDel(ids);
    }
}
